package com.dao;

import com.entity.user;

import java.util.List;

public class rechangedaoimpl implements rechangedao{
    @Override
    public boolean rechange(String money,String id) {
        boolean flag =true;
        double m = Double.parseDouble(money);
        String sql1="update user set Money=Money+? where UserID=?";
        UserInfDao u=new UserInfDao();
        u.update(sql1,m,id);
        return flag;
    }

    @Override
    public boolean pay(String money,String id,String id1) {
        boolean flag1=true;
        String sql2="select Money from user where UserID=?";
        UserInfDao us=new UserInfDao();
        List<user> list =us.getForList(user.class,sql2,id);
        double n = Double.parseDouble(money);
        for (int i = 0; i < list.size(); i++) {
            double m = Double.parseDouble(list.get(i).getMoney());
            if(m<n){
                flag1=false;
            }
            else
            {
                String sql3="update user set Money=Money-? where UserID=?";
                String sql4="update user set Money=Money+? where UserID=?";
                us.update(sql3,n,id);
                us.update(sql4,n,id1);
            }
        }
        return flag1;
    }
}
